class Solution
{
public:
    int bestClosingTime(string customers)
    {
        int cost = 0;
        for (char c : customers)
        {
            if (c == 'Y')
            {
                ++cost;
            }
        }
        int minCost = cost;
        int bestTime = 0;
        for (int i = 1; i <= customers.size(); ++i)
        {
            if (customers[i - 1] == 'Y')
            {
                --cost;
            }
            else
            {
                ++cost;
            }
            if (minCost > cost)
            {
                minCost = cost;
                bestTime = i;
            }
        }
        return bestTime;
    }
};